#include <gtest/gtest.h>

#include "Utility/FileSystem/SGFileSystem.h"

TEST (Filesystem, getCurrentExecutablePath)
{
    auto currentExecutablePath = SG::Utility::FileSystem::getCurrentExecutablePath ();
    //std::cout << currentExecutablePath << std::endl;
    ASSERT_TRUE (currentExecutablePath.find ("/bin") != std::string::npos || currentExecutablePath.find ("\\bin") != std::string::npos);
}

TEST (Filesystem, getFilesWithExtension)
{
    auto filefold = SG::Utility::FileSystem::getTestDataPath ("Infrastructure/BasicTools");
    auto files    = SG::Utility::FileSystem::getFilesWithExtension (filefold, ".test");
    auto len      = files[0].length ();
    ASSERT_STREQ (files[0].substr (len - 26).c_str (), "getFilesWithExtension.test");
    ASSERT_EQ (files.size (), 1);
}

TEST (Filesystem, extractDirectoryAndFileName)
{
    std::string directoryPath;
    std::string fileName;

#if defined(_WIN32)
    const char* filePath = "C:\\Users\\test\\test.txt";
    SG::Utility::FileSystem::extractDirectoryAndFileName (filePath, directoryPath, fileName);
    ASSERT_STREQ (directoryPath.c_str (), "C:\\Users\\test");
    ASSERT_STREQ (fileName.c_str (), "test.txt");
#endif

    const char* filePath2 = "/Users/test/test.txt";
    SG::Utility::FileSystem::extractDirectoryAndFileName (filePath2, directoryPath, fileName);
    ASSERT_STREQ (directoryPath.c_str (), "/Users/test");
    ASSERT_STREQ (fileName.c_str (), "test.txt");

    const char* filePath3 = "test.txt";
    SG::Utility::FileSystem::extractDirectoryAndFileName (filePath3, directoryPath, fileName);
    ASSERT_STREQ (directoryPath.c_str (), "");
    ASSERT_STREQ (fileName.c_str (), "test.txt");

    const char* filePath4 = "./test.txt";
    SG::Utility::FileSystem::extractDirectoryAndFileName (filePath4, directoryPath, fileName);
    ASSERT_STREQ (directoryPath.c_str (), ".");
    ASSERT_STREQ (fileName.c_str (), "test.txt");
}
